package cn.etgps.etgps.blmanager;

import android.content.Context;
import android.content.SharedPreferences;

import cn.etgps.etgps.R;
import cn.etgps.etgps.utils.AppUtils;
import cn.etgps.etgps.utils.Constant;

/**
 * loading page manager
 *
 * @author nicky.han
 */
public class LoadingManager extends BaseBLManager {
    /**
     * Constructor method
     */
    public LoadingManager(Context context) {
        super(context);
    }


    /**
     * Check if it is the first time to run this application
     */
    public boolean isFirstRun() {
        SharedPreferences mPerference = mContext.getSharedPreferences(
                mContext.getResources().getString(R.string.preference_key), Context.MODE_PRIVATE);
        String key = mContext.getResources().getString(R.string.key_first_run);
        String result = mPerference.getString(key, "");
        if (result.equals("")) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Change is the first time to run
     */
    public void EditIsFirstRun() {
        SharedPreferences mPerference = mContext.getSharedPreferences(
                mContext.getResources().getString(R.string.preference_key), Context.MODE_PRIVATE);
        String key = mContext.getResources().getString(R.string.key_first_run);
        String result = mPerference.getString(key, "");
        if (result.equals("")) {
            SharedPreferences.Editor editor = mPerference.edit();
            editor.putString(key, key);
            editor.commit();
            Constant.URI_BASH_PATH = "http://www.itte.net.cn:80/vehicleapi/WebService/";
            AppUtils.setPath();
        }
    }

    public void setIpPort() {
        SharedPreferences mPerference = mContext.getSharedPreferences(
                mContext.getResources().getString(R.string.preference_key), Context.MODE_PRIVATE);
        String ip = mPerference.getString(mContext.getString(R.string.label_system_set_ip), "");
        String port = mPerference.getString(mContext.getString(R.string.label_system_set_port), "");
        Constant.URI_BASH_PATH = "http://" + ip + ":" + port + "/vehicleapi/WebService/";
        AppUtils.setPath();
    }
}
